//
//  AddPersonViewController.m
//  PeopleFinder
//
//  Created by Mark Pavlidis on 1/30/2010.
//  Copyright 2010 Pavlidis Consulting. All rights reserved.
//

#import "AddPersonViewController.h"
#import "SimilarPeopleTableViewController.h"

@implementation AddPersonViewController

@synthesize addButton;
@synthesize firstNameTextField;
@synthesize lastNameTextField;


 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc {
	[addButton release];
	[firstNameTextField release];
	[lastNameTextField release];
    [super dealloc];
}



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)viewDidAppear:(BOOL)animated {
	[firstNameTextField becomeFirstResponder];
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}

#pragma mark -
#pragma mark UITextViewDelegate methods

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	if (textField == firstNameTextField) {
		// the user presses "Next", go to the family name
		[textField resignFirstResponder];
		[lastNameTextField becomeFirstResponder];
	} else if (textField == lastNameTextField) {			
		// the user pressed the "Go" button, so dismiss the keyboard
		[textField resignFirstResponder];
		[self addPerson:nil];
	}
	return YES;
}


#pragma mark -
#pragma mark UI actions

- (IBAction)addPerson:(id)sender {
	SimilarPeopleTableViewController *sptvc = [[SimilarPeopleTableViewController alloc] initWithNibName:@"SimilarPeopleTableViewController" bundle:nil];
	[self.navigationController pushViewController:sptvc animated:YES];
	[sptvc release];
}

#pragma mark -
#pragma mark UITouch Methods

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	[firstNameTextField resignFirstResponder];
	[lastNameTextField resignFirstResponder];
}
 
@end
